var services=angular.module('guthub.services',['ngResource']);
services.factory('Recipe',['$resource',function($resource){
    return $resource('http://localhost/yonps/index.php/home/index/gets4/:id',{id:'@id'});
}]);
services.factory('Items',['$resource',function($resource){
    var items={};
    items.query=function(){
        return[
            {id:1,name:"yonps",age:22},
            {id:2,name:"sgh",age:23},
            {id:3,name:"dcy",age:21},
            {id:4,name:"hff",age:20},
        ];
    };
    items.select=function(){
        var res=$resource('http://localhost/yonps/test/ajax.php');
        var data=res.query({},function(data){
            console.log(data);
        });
        return data;
    };
    items.find=function(){
        var res=$resource('http://localhost/yonps/index.php/home/index/gets4');
        var list=res.query({"name":"yonps"},function(data){
            console.log(data);
        },function(error){
            console.log("error");
        });
        return list;
    }
    return items;
}]);
services.factory('MultRecipeLoader',['Recipe','$q',function(Recipe,$q){
    return function(){
        var delay=$q.defer();
        Recipe.query(function(recipes){
            delay.resolve(recipes);
        },function(){
            delay.reject('query error');
        });
        return delay.promise;
    };
}]);
services.factory('RecipeLoader',['Recipe','$stateParams','$q',function(Recipe,$stateParams,$q){
    return function(){
        var delay=$q.defer();
        Recipe.get({"recipeId":$stateParams.id},function(recipe){
            delay.resolve(recipe);
        },function(){
            delay.reject("get error");
        });
        return delay.promise;
    };
}]);